<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>09.静态方法中的each方法.html</title>
</head>
<script src="./js/jquery-1.12.4.js"></script>
<script>
    var arr = [1, 3, 5, 7, 9];
    var obj = {
            0: 20,
            1: 10,
            2: 5,
            3: 8,
            4: 20,
            length: 5,
        }
        //1.用原生JS的foreach遍历数组,不可以遍历对象
    arr.forEach(function(value, index) { //value值，index下标
            console.log(value, index);
        })
        // obj.forEach(function(value, index) {
        //     console.log(value, index);
        // })
        //2.用Jquery遍历数组
        /* 
         *each方法可以遍历数组，同时也可以遍历伪数组
         */
    $(function() {
        $.each(arr, function(index, value) { //index和value的值正好和js的foreach相反
            console.log(index, value);
        })
        console.log("+++++++++++++++++++")
        $.each(obj, function(index, value) {
            console.log(index, value);
        })
    })
</script>

<body>

</body>

</html>